//商品集

var warehouse =require('./warehouse_merchants.js')
var mongoose=require('mongoose')
//连接数据库
var db=mongoose.createConnection('mongodb://127.0.0.1:27017/warehouse')

var newScheam=mongoose.Schema({
	_id:String,//Id
	index:Number,
	title:String,//商品名
	classes:String,//类别
	price:Number,//价格
	salesVolume:Number,//销量
	img:String,//展示图
	businessName:String,//商家店名
	businessID:String//商家Id
})
//关联表(集合) 
var mode=db.model('goods',newScheam)

class operation {
	constructor(mode) {
		this.mode=(parms)=>{
			return new mode(parms);
		}
	};
	//数据查询
	find(start,end){
		return mode.find({},{'_id':false,'__v':false}).skip(start).limit(end);
	}
	//更新数据	
	update(list){
		return new mode({
			index:list.index,
			_id:list._id,
			title:list.title,
			classes:list.classes,
			price:list.price,
			salesVolume:list.salesVolume,
			img:list.img,
			businessName:list.businessName,
			businessID:list.businessID
		}).save()
	}
	//卸载数据
	remove(){
		return new Promise((resolve,reject)=>{
			mode.remove({},(err)=>{
				if(err) reject(false)
				resolve(true)
			})
		})
	}
}

module.exports=new operation()